package org.urchr.beorganized.api.impl.agenda;

import java.util.StringTokenizer;

import org.urchr.beorganized.api.base.PrivateBaseAPIServlet;
import org.urchr.beorganized.dao.NotesDAO;
import org.urchr.beorganized.dao.XMLDocumentBuilder;
import org.urchr.beorganized.dao.errors.GeneralException;

public class CompleteTasks extends PrivateBaseAPIServlet {

	public CompleteTasks() {
		skipBody = true;
	}
	
	@Override
	protected void doProcessPrivate() throws GeneralException {
		String noteIDs = getParameter("noteids");
		if(null==noteIDs)
			noteIDs = "";
//		System.out.println("ids: "+noteIDs);
		StringTokenizer st = new StringTokenizer(noteIDs, ",");
		while(st.hasMoreTokens()){
			String token = st.nextToken().trim();
			int noteID = NotesDAO.safeInt(token, -1);
//			System.out.println("Completing: "+noteID+": "+token);
			NotesDAO.completeTask(noteID, userID);
		}
		sendNode(new XMLDocumentBuilder().getRootElement("ok"));
	}

}
